#!/usr/bin/env python3
# -*-coding:utf-8 -*-
# __author__=LuLu
from page.basePage import BasePage
from pagesLocators.loginLocators import LoginLoc as Loc
from comment.readYaml import ReadYaml


class Login(BasePage):

    # 打开登录页
    def open_login_url(self):
        self.visit_url(f'{ReadYaml().get_host()}/ucenter/login')

    # 输入用户名
    def input_username(self, values):
        self.clear_element(Loc.user_name)
        self.sendKey_element(Loc.user_name, values)

    # 输入密码
    def input_password(self, values):
        self.clear_element(Loc.password)
        self.sendKey_element(Loc.password, values)

    # 输入验证码
    def input_auth_key(self, values):
        self.clear_element(Loc.verification_code_input)
        self.sendKey_element(Loc.verification_code_input, values)

    # 点击登录按钮
    def click_login_button(self):
        self.click_element(Loc.login_button)

    # 获取copy_right
    def get_copy_right(self):
        return self.get_element_value(Loc.copy_right)

    # 获取登录用户名/密码空提示
    def get_warn(self):
        return self.get_element_value(Loc.warn)

    # # 获取登录密码空提示
    # def get_warn_password(self):
    #     return self.get_element_value(Loc.warn_password)
    # 获取跳转链接
    def copy_right_turn_to(self):
        return self.get_element_attribute(Loc.copy_right_turn_to, 'href')

    # 退出登录
    def logout(self):
        self.click_element(Loc.logout_button)

    # # 基础登录
    # def base_login(self, name, password):
    #     """作为测试其他页面的基础"""
    #     self.visit_url(f'{Tools().get_host()}/ucenter/login')
    #     self.input_username(name)
    #     self.input_password(password)
    #     # self.input_auth_key(auth_key)
    #     self.click_login_button()

    # 获取登录失败提示框
    def get_login_error(self):
        return self.get_element_value(Loc.error_login)
